Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct return type of asynccontextmanager in 3.10 #6634

Merged
merged 2 commits into from
Dec 20, 2021

Conversation

AlexWaygood
Copy link
Member

Fixes #6625 (I think)

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/vendor/decorator.py:279: error: Module "contextlib" has no attribute "GeneratorContextManager"; maybe "_GeneratorContextManager", "ContextManager", or "AbstractContextManager"?
+ pyinstrument/vendor/decorator.py:279: error: Module "contextlib" has no attribute "GeneratorContextManager"; maybe "_GeneratorContextManager", "_AsyncGeneratorContextManager", or "ContextManager"?

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a _GeneratorContextManagerBase base class for both _GeneratorContextManager and _AsyncGeneratorContextManager (on Python 3.9), which is worth considering for a future PR.

@srittau srittau merged commit 2173c44 into python:master Dec 20, 2021
@AlexWaygood AlexWaygood deleted the contextlib branch December 20, 2021 17:19
@AlexWaygood
Copy link
Member Author

There's also a _GeneratorContextManagerBase base class for both _GeneratorContextManager and _AsyncGeneratorContextManager (on Python 3.9), which is worth considering for a future PR.

Well, I had a go. You can see the results in a branch over here -- but I'm not really sure it's worth worrying about, since it seems like it breaks mypy :/

Even after adding 5 # type: ignores I get

stdlib\contextlib.pyi:50: error: INTERNAL ERROR -- Please try using mypy master on Github

when I try to run mypy on it.

@hauntsaninja
Copy link
Collaborator

Do you have a full stack trace on hand?

@JelleZijlstra
Copy link
Member

For what it's worth, I don't think it's too important to add the _GeneratorContextManagerBase base class since it's private and provides no public methods.

@AlexWaygood
Copy link
Member Author

Do you have a full stack trace on hand?

Here's a full traceback:

(.venv3) C:\Users\Alex\Desktop\Code dump\typeshed>mypy test.py --custom-typeshed-dir . --tb
stdlib\contextlib.pyi:49: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.920
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "mypy\semanal.py", line 4990, in accept
  File "mypy\nodes.py", line 959, in accept
  File "mypy\semanal.py", line 1078, in visit_class_def
  File "mypy\semanal.py", line 1100, in analyze_class
  File "mypy\semanal.py", line 1330, in clean_up_bases_and_infer_type_variables
AssertionError: mypy does not currently support ParamSpec use in generic classes
stdlib\contextlib.pyi:49: : note: use --pdb to drop into pdb
  • Python version: 10.1
  • mypy version: 0.920
  • Command run: mypy test.py --custom-typeshed-dir . --tb (test.py being an empty file in the root folder of my typeshed clone).

@hauntsaninja
Copy link
Collaborator

Okay, so should be fixed come 0.930

@ljodal
Copy link

ljodal commented Dec 22, 2021

Fixes #6625 (I think)

I can confirm that it fixes the issue in my codebase. Thanks for the fix! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AsyncContextManager is not callable error when used as decorator
5 participants